##################################################
# Replication Code
# Taeyong Park and Andrew Reeves
# "Local Unemployment and Voting for President: Uncovering Causal Mechanisms"
# Summary: Produces a summary table of the estimated results (AME, ADE, ATE)  
##################################################

intervalEst = function(data){
  dataATE<-matrix(NA, nrow=nrow(data), ncol=ncol(data)/3)
  dataAME<-matrix(NA, nrow=nrow(data), ncol=ncol(data)/3)
  dataADE<-matrix(NA, nrow=nrow(data), ncol=ncol(data)/3)
  for (i in 1:(ncol(data)/3)){
    dataATE[,i] <- data[,(i-1)*3+1]
    dataAME[,i] <- data[,(i-1)*3+2]
    dataADE[,i] <- data[,(i-1)*3+3]
  }
  meanATE<-mean(dataATE)
  meanAME<-mean(dataAME)
  meanADE<-mean(dataADE)
  lowerATE95<-quantile(dataATE, 0.025)
  upperATE95<-quantile(dataATE, 0.975)
  lowerAME95<-quantile(dataAME, 0.025)
  upperAME95<-quantile(dataAME, 0.975)
  lowerADE95<-quantile(dataADE, 0.025)
  upperADE95<-quantile(dataADE, 0.975)
  lowerATE90<-quantile(dataATE, 0.05)
  upperATE90<-quantile(dataATE, 0.95)
  lowerAME90<-quantile(dataAME, 0.05)
  upperAME90<-quantile(dataAME, 0.95)
  lowerADE90<-quantile(dataADE, 0.05)
  upperADE90<-quantile(dataADE, 0.95)
  
  coefTable <- cbind(meanAME,
                     meanADE,
                     meanATE)
  seTable <- cbind(lowerAME95,
                   upperAME95,
                   lowerADE95,
                   upperADE95,
                   lowerATE95,
                   upperATE95)
  seTable2 <- cbind(lowerAME90,
                    upperAME90,
                    lowerADE90,
                    upperADE90,
                    lowerATE90,
                    upperATE90)
  return(list(coefTable, seTable, seTable2))
}